package cn.sxgan.gen.controller;

import cn.sxgan.gen.model.DbTable;
import cn.sxgan.gen.services.base.DataSourceQueryFactory;
import cn.sxgan.gen.services.base.DataSourceService;
import cn.sxgan.gen.services.core.CodeGeneratorService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Description: 生成控制器
 * @Author: sxgan
 * @Date: 2025-07-17 17:42
 * @Version: 1.0
 **/
@Slf4j
@Controller
@RequestMapping("/generate")
public class GenerateController {
    
    @Autowired
    private CodeGeneratorService codeGenerator;
    
    @Autowired
    private DataSourceService dataSourceService;
    
    
    @Autowired
    DataSourceQueryFactory dataSourceQueryFactory;
    
    
    @ResponseBody
    @PostMapping("/genCodeByTable")
    public void generateCode(HttpServletResponse response, @RequestBody DbTable dbTable) throws Exception {
        codeGenerator.generateSingleTable(response, dbTable);
    }
    
    @ResponseBody
    @PostMapping("/genCodeByTables")
    public void generateCode(HttpServletResponse response, @RequestBody List<DbTable> dbTables) throws Exception {
        codeGenerator.generateMultiTable(response, dbTables);
    }
}